<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加积分审批流程节点' : '修改积分审批流程节点' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules">
					
					<a-form-model-item label="课程类型" prop="activityTypeID">
						<a-select v-model="form.activityTypeID">
							<template v-for="(item, index) in ActivityTypeData">
								<a-select-option :key="item.ID">{{ item.Name }}</a-select-option>
							</template>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="审批类型" prop="CreditFlowTypeID">
						<a-select optionFilterProp="children" showSearch v-model="form.CreditFlowTypeID" >
							<template v-for="(item, index) in CreditFlowTypeData">
								<a-select-option :key="item.ID">{{ item.Name }}</a-select-option>
							</template>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
import { ManageCreditApplyFlowDoAdd, UpdateApplyActivityFlow } from '@/api/follow';
export default {
	props: {
		text: Object,
		ActivityTypeData: Array,
		CreditFlowTypeData: Array,
		activityTypeID: String
	},
	watch: {
		text: function(text) {
			if (JSON.stringify(text) == '{}') {
				this.form.activityTypeID = this.activityTypeID;
			} else {
				this.form = text;
				this.form.activityTypeID = this.activityTypeID;
			}
		}
	},
	data() {
		return {
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			DepartmenDropdowntList: [],
			form: {
				activityTypeID: '',
				ActivityFlowTypeID: ''
			},
			rules: {
				activityTypeID: [
					{
						required: true,
						message: '请选择课程类型',
						trigger: 'change'
					}
				],
				CreditFlowTypeID: [
					{
						required: true,
						message: '请选择审批类型',
						trigger: 'change'
					}
				]
			}
		};
	},
	created() {},
	methods: {
		closeFunction(data) {
			this.$emit('closeFun', data);
			this.form = {};
		},
		handleSubmit(e) {
			this.$refs.ruleForm.validate(async valid => {
				if (valid) {
					let data = this.form;
					let res = {};
					if (JSON.stringify(this.text) == '{}') {
						res = await ManageCreditApplyFlowDoAdd(data);
					} else {
						res = await UpdateApplyActivityFlow(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
				} else {
					return false;
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
/deep/.ant-form-item {
	margin: 20px 50px;
	display: flex;
}
/deep/.ant-form-item-label {
	width: 120px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}

.ant-form-item {
	margin-bottom: 10px;
}

/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
</style>
